<template>
  <div class="editor-wrapper">
    <div id="editor" type="text/plain" style="height: 100%;"></div>
  </div>
</template>

<script setup>
import {onBeforeUnmount, onMounted} from "vue";

let editor = {}

onMounted(() => {
  if (window.UE) {
    editor = window.UE.getEditor("editor");
    window.editor = editor
    window.domUtils = window.UE.dom.domUtils;
  }
});

function getContent() {
  if (editor) {
    return editor.getContent()
  }
  return ''
}

function setContent(html, isAppend = true) {
  if (editor) {
    editor.setContent(html, isAppend)
  }
}

defineExpose({
  setContent,
  getContent
})

onBeforeUnmount(() => {
  window.UE.delEditor('editor')
})
</script>

<style lang="less">
.editor-wrapper ,.edui-default ,#edui1_iframeholder{
  height: 100%;
}
.editor-wrapper .edui-default .edui-editor{
  border: none;
}
.editor-wrapper .edui-editor-iframeholder{
  height: calc(100% - 70px) !important;
}

ul.bh-insert-link{
  padding: 20px 10px 0;
}
ul.bh-insert-link, ul.bh-insert-link li{
  list-style: none;
}
ul.bh-insert-link li{
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
ul.bh-insert-link li:nth-child(2){
  margin-bottom: 10px;
}
ul.bh-insert-link li label{
  display: inline-block;
  box-sizing: border-box;
  width: 100px;
  padding-right: 10px;
  text-align: right;
}
ul.bh-insert-link li input{
  flex-grow: 1;
  height: 32px;
  line-height: 32px;
  padding: 0 10px;
  border-radius: 5px;
  border: 1px solid #DDDDDD;
}

.emoji-wrapper table img{
  width: 22px;
  vertical-align: middle;
}
.emoji-wrapper table{
  border: 1px solid #ddd;
  border-collapse: collapse;
}
.emoji-wrapper td{
  padding: 3px 4px;
  border: 1px solid #ddd;
  text-align: center;
}
.emoji-wrapper td:hover{
  background: #b6e2fa;
  cursor: pointer;
}
.emoji-wrapper{
  min-height: 60px;
  overflow-y: auto;
  position: relative;
}
.emoji-wrapper .show-image-detail.pos-left{
  top: 0;
  left: 0;
}
.emoji-wrapper .show-image-detail{
  position: absolute;
  right: 0;
  top: 0;
  width: 70px;
  height: 70px;
  border: 2px solid #09a0f1;
  background: #ffffff;
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 2px;
  display: none;
}
.emoji-wrapper .show-image-detail img{
  max-width: 60px;
  max-height: 60px;
}
.editContent{
  display: none !important;
  width: 0;
  height: 0;
}
.edui-default .edui-editor-iframeholder{
  width: 100% !important;
  padding: 15px;
}
/* 上传组件样式 */
.bh-editor-upload-content{
  padding: 20px;
}
.bh-editor-image-upload-wrapper{
  display: flex;
  align-items: center;
}
.bh-editor-image-upload-wrapper>input{
  flex-grow: 1;
  margin: 0 20px;
  border: 1px solid #eee;
  height: 30px;line-height: 30px;
  border-radius: 5px;
  outline: none;
  padding: 0 15px;
}
.bh-editor-image-upload-wrapper label{
  height: 30px;line-height: 30px;
  text-align: center;
  border: 1px solid #eee;
  border-radius: 5px;
  display: block;
  padding: 0 20px;
  cursor: pointer;
}
.bh-editor-image-upload-wrapper label input[type="file"] {
  display: none;
}
.bh-editor-image-upload-wrapper label:hover{
  background: #ddd;
}
.bh-editor-image-preview{
  height: 360px;
  overflow: hidden;
  position: relative;
  background-color: #f1f1f1;
  border: 1px solid #eee;
  padding: 20px;
  margin-top: 20px;
}
.bh-editor-image-preview img{
  max-width: calc(100% - 40px);
  max-height: calc(100% - 40px);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.bh-editor-image-preview span{
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-size: 20px;
}
#edui1{
  height: 100%;
}

</style>